package com.dunqi.gpm.shunqing.develop.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.dunqi.gpm.shunqing.R;
import com.dunqi.gpm.shunqing.common.base.RecyclerAdapter;
import com.dunqi.gpm.shunqing.common.util.Arith;
import com.dunqi.gpm.shunqing.develop.bean.EarlyWarning;

import java.util.List;

/**
 * Created by 空 on 2017/12/11 0011.
 */
public class EarlyWarningAdapter extends RecyclerAdapter<EarlyWarning> {

    private int[] resIds;

    public EarlyWarningAdapter(@Nullable List<EarlyWarning> data) {
        super(R.layout.item_early_warning, data);
        resIds = new int[]{R.mipmap.yub, R.mipmap.yuy, R.mipmap.yur};
    }

    @Override
    protected void convert(BaseViewHolder helper, EarlyWarning item) {
        Integer blue = item.getAlarmStatusBlue();
        Integer yellow = item.getAlarmStatusOrange();
        Integer red = item.getAlarmStatusRed();

        TextView redTv = helper.getView(R.id.red_tv);
        TextView blueTv = helper.getView(R.id.blue_tv);
        TextView yellowTv = helper.getView(R.id.yellow_tv);

        setColorNum(yellow, yellowTv);
        blue = null;
        setColorNum(blue, blueTv);
        setColorNum(red, redTv);

        int alarmStatus = item.getAlarmStatus();
        alarmStatus--;
        if (alarmStatus < 0) {
            alarmStatus = 0;
        }

        /**
         * 2018年2月1日10:18:07
         */
        if (alarmStatus == 0) {
            helper.getView(R.id.alarm_iv).setVisibility(View.INVISIBLE);
        } else {
            helper.getView(R.id.alarm_iv).setVisibility(View.VISIBLE);
        }

        helper.setImageResource(R.id.alarm_iv, resIds[alarmStatus]);

        helper.setText(R.id.title_tv, item.getProjectName())
                .setText(R.id.company_tv, "责任单位:" + item.getRespOrgName())
                .setText(R.id.money_tv, "项目投资:" + Arith.get2Double(item.getTotalInvestmentAmount()) + " 万元");
    }

    private void setColorNum(Integer yellow, TextView yellowTv) {
        if (yellow == null) {
            yellowTv.setVisibility(View.GONE);
        } else {
            yellowTv.setVisibility(View.VISIBLE);
            if (yellow < 10) {
                yellowTv.setText(" " + yellow);
            } else {
                yellowTv.setText("" + yellow);
            }
        }
    }
}
